﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WindowsGame1
{
    public class StateShootStarPattern : State
    {
        public float delay = 0;
        public float delayUntilNextPattern = 0.3f;
        public int waveCount = 5;
        public float angleOrigin = 0;
        public float angleRotationIncrement = 16;
        public float fov = 180;
        public float fovIncrement = 18;
        int waveIndex = 0;

        public StateShootStarPattern(Alien a)
            : base(a)
        {

        }

        public override bool Update(Timer t)
        {
            angleOrigin += t.Delta * angleRotationIncrement;
            delay -= t.Delta;

            if (delay < 0)
            {
                waveIndex++;
                delay = delayUntilNextPattern;
                if (waveIndex % waveCount == 0)
                    delay = delayUntilNextPattern * 8;

                for (float i = -fov; i < +fov; i += fovIncrement)
                {
                    Bullet b = Bullet.CreateFatBullet();
                    b.owner = alien;
                    b.pos = alien.pos;
                    b.speed = 125;

                    Matrix rot = Matrix.CreateRotationZ(MathHelper.ToRadians(i) + angleOrigin);
                    Vector3 dir = Vector3.Transform(new Vector3(0, 1, 0), rot);

                    b.dir = new Vector2(dir.X, dir.Y);
                    Game1.instance.alienBulletManager.bullets.Add(b);
                }

            }

            return true;
        }
    }
}
